home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr47 / alt_lan.zip / SATHER.ASC < prev    next >
Text File  |  1993-09-17  |  2KB  |  114 lines

  1. _THE SATHER PROGRAMMING LANGUAGE_
  2. by  Stephen M. Omohundro
  3.  
  4. [LISTING ONE]
  5.  
  6. class STACK{T} is
  7.    -- Stacks of elements of type T.
  8.    attr s:ARR{T};       -- An array containing the elements.
  9.    attr size:INT;       -- The current insertion location.
  10.  
  11.    is_empty:BOOL is
  12.       -- True if the stack is empty.
  13.       res := (s=void or size=0) end;
  14.  
  15.    pop:T is
  16.       -- Return the top element and remove it. Void if empty.
  17.       if is_empty then res:=void
  18.       else size:=size-1; res:=s[size]; s[size]:=void end end;
  19.    
  20.    push(T) is
  21.       -- Push arg onto the stack.
  22.       if s=void then s:=#ARR{T}(asize:=5)
  23.       elsif size=s.asize then double_size end;
  24.  
  25.       s[size]:=arg; size:=size+1 end;
  26.  
  27.    private double_size is
  28.       -- Double the size of `s'.
  29.       ns::=#ARR{T}(asize:=2*s.asize); ns.copy_from(s); s:=ns end;
  30.  
  31.    clear is
  32.       -- Empty the stack.
  33.       size:=0; s.clear end
  34.    
  35. end; -- class STACK{T}
  36.  
  37. class FOO is
  38.    bar is 
  39.       s1:STACK{CHAR}; s1.push('a');
  40.       s2:STACK{STR};  s2.push("This is a string.") end;
  41. end;
  42.  
  43.  
  44.  
  45. [LISTING TWO]
  46.  
  47. abstract class $POLYGON is
  48.    ...
  49.    number_of_vertices:INT;
  50. end;
  51.  
  52. class TRIANGLE is
  53.    inherit $POLYGON;
  54.    ...
  55.    number_of_vertices:INT is res:=3 end;
  56. end;
  57.  
  58. class SQUARE is
  59.    inherit $POLYGON;
  60.    ...
  61.    number_of_vertices:INT is res:=4 end;
  62. end;
  63.  
  64. class FOO2 is
  65.    bar2 is
  66.       s:STACK{$POLYGON};
  67.       ...
  68.       n:=s.pop.number_of_vertices;
  69.       ... 
  70.    end;
  71. end;
  72.  
  73.  
  74. [LISTING THREE]
  75.  
  76. >5+7
  77. 12
  78.  
  79. >40.intinf.factorial
  80. 815915283247897734345611269596115894272000000000
  81.  
  82. >#OUT + "Hello world!"
  83. Hello world!
  84.  
  85. >v::=#VEC(1.0,2.0,3.0); w::=#VEC(1.0,2.0,3.0); 
  86. >v+w
  87. #VEC(2.0, 4.0, 6.0)
  88.  
  89. >v.dot(w)
  90. 14.0
  91.  
  92. >#ARRAY{STR}("grape", "cherry", "apple", "plum", "orange").sort
  93. #ARRAY{STR}("apple","cherry","grape","orange","plum")
  94.  
  95.  
  96.  
  97. [LISTING FOUR]
  98.  
  99. >loop #OUT+1.upto!(9) end
  100.  
  101. 123456789 
  102.  
  103. >a::=#ARRAY{INT}(asize:=10)
  104. >loop a.set_elts!(1.upto!(10)) end
  105. >a
  106. #ARRAY{INT}(1,2,3,4,5,6,7,8,9,10)
  107.  
  108. >loop a.set_elts!(2*a.elts!) end
  109. >a
  110. #ARRAY{INT}(2,4,6,8,10,12,14,16,18,20)
  111.  
  112.  
  113.  
  114.